package com.neu.questionnaireplus.config.schedule;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class AsyncConfig {

  @Value("${task.coreSize}")
  private int corePoolSize;
  @Value("${task.maxPoolSize}")
  private int maxPoolSize;
  @Value("${task.queueCapacity}")
  private int queueCapacity;

  /** 
  * @Description: 配置线程池，保证多线程运行效率 
  * @Param: [] 
  * @return: java.util.concurrent.Executor 
  * @Author: ~FHX~ (:TSunS:)
  * @Date: 2022/10/26 
  */ 
  
  @Bean
  public Executor taskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setMaxPoolSize(maxPoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.initialize();
    return executor;
  }
}

